<!DOCTYPE html>






<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />


















  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="chrome,js,indexedDB,算法," />










<meta name="description" content="有时候会了解一些项目或者工作中用不到小知识点这里就是存放它的小盒子希望能塞的满满的">
<meta name="keywords" content="chrome,js,indexedDB,算法">
<meta property="og:type" content="article">
<meta property="og:title" content="new Get">
<meta property="og:url" content="https://zhangyuhan2016.gitee.io/2017/12/14/new-Get/index.html">
<meta property="og:site_name" content="zhangyuhan2016">
<meta property="og:description" content="有时候会了解一些项目或者工作中用不到小知识点这里就是存放它的小盒子希望能塞的满满的">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://zhangyuhan2016.gitee.io/images/sort.png">
<meta property="og:updated_time" content="2018-11-28T05:25:06.223Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="new Get">
<meta name="twitter:description" content="有时候会了解一些项目或者工作中用不到小知识点这里就是存放它的小盒子希望能塞的满满的">
<meta name="twitter:image" content="https://zhangyuhan2016.gitee.io/images/sort.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zhangyuhan2016.gitee.io/2017/12/14/new-Get/"/>





  <title>new Get | zhangyuhan2016</title>









</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<header style="position: fixed;z-index: 99999999;background-color: #eee;width: 100%;text-align: center;">
    <h3>感谢您的关注，最新博客已迁移至 <mark style="background-color: #07c160;padding: 4px;"><a style="color: #fff;" href="https://blog.hi-zhang.com" target="_blank">blog.hi-zhang.com</a></mark> </h3>
</header>






  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">


    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">zhangyuhan2016</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>

        <p class="site-subtitle"></p>

  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">



    <ul id="menu" class="menu">


        <li class="menu-item menu-item-home">
          <a href="/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />

            首页
          </a>
        </li>


        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />

            标签
          </a>
        </li>


        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />

            归档
          </a>
        </li>



    </ul>



</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">


  <div id="posts" class="posts-expand">








  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">



  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zhangyuhan2016.gitee.io/2017/12/14/new-Get/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="zhangyuhan2016">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="zhangyuhan2016">
    </span>


      <header class="post-header">



          <h1 class="post-title" itemprop="name headline">new Get</h1>


        <div class="post-meta">
          <span class="post-time">

              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>

                <span class="post-meta-item-text">发表于</span>

              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-14T11:41:02+08:00">
                2017-12-14
              </time>



              <span class="post-meta-divider">|</span>



              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>

                <span class="post-meta-item-text">更新于&#58;</span>

              <time title="更新于" itemprop="dateModified" datetime="2018-11-28T13:25:06+08:00">
                2018-11-28
              </time>

          </span>





              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/12/14/new-Get/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2017/12/14/new-Get/" itemprop="commentCount"></span>
                </a>
              </span>





             <span id="/2017/12/14/new-Get/" class="leancloud_visitors" data-flag-title="new Get">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>

                 <span class="post-meta-item-text">阅读次数&#58;</span>

                 <span class="leancloud-visitors-count"></span>
             </span>





            <div class="post-wordcount">


                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>

                  <span class="post-meta-item-text">字数统计&#58;</span>

                <span title="字数统计">
                  2,360
                </span>



                <span class="post-meta-divider">|</span>



                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>

                  <span class="post-meta-item-text">阅读时长 &asymp;</span>

                <span title="阅读时长">
                  13
                </span>

            </div>




        </div>
      </header>





    <div class="post-body" itemprop="articleBody">





        <blockquote class="blockquote-center"><p>有时候会了解一些项目或者工作中用不到小知识点<br>这里就是存放它的小盒子<br>希望能塞的满满的</p>
</blockquote>
<a id="more"></a>
<h3 id="Vue调用组件函数"><a href="#Vue调用组件函数" class="headerlink" title="Vue调用组件函数"></a>Vue调用组件函数</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// a</span><br><span class="line">&lt;template ref=&apos;a&apos;&gt;&lt;/template&gt;</span><br><span class="line">// b</span><br><span class="line">this.$refs.a.xxx()</span><br></pre></td></tr></table></figure>
<h3 id="Unicode与JavaScript"><a href="#Unicode与JavaScript" class="headerlink" title="Unicode与JavaScript"></a>Unicode与JavaScript</h3><p>需求： 截取用户昵称得第一个字符突出显示</p>
<p>用户昵称示例： “Aslar” “❤love” “😋sm”</p>
<p>如下代码：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&gt;&gt; <span class="string">"😋"</span>.substr(<span class="number">0</span>,<span class="number">1</span>)</span><br><span class="line">&lt;&lt; <span class="string">"�"</span></span><br><span class="line">&gt;&gt; <span class="string">"😋"</span>.length</span><br><span class="line">&lt;&lt; <span class="number">2</span></span><br><span class="line">&gt;&gt; <span class="built_in">Array</span>.from(<span class="string">"😘"</span>).length</span><br><span class="line">&lt;&lt; <span class="number">1</span></span><br></pre></td></tr></table></figure></p>
<p>如何显示表情符号</p>
<ol>
<li>通过获取chartCodeAt 判断</li>
<li>Array.from(“😘”)[0]</li>
</ol>
<p>参考资料： </p>
<ul>
<li><a href="http://www.ruanyifeng.com/blog/2014/12/unicode.html" target="_blank" rel="noopener">Unicode与JavaScript详解</a></li>
</ul>
<h3 id="时间格式化"><a href="#时间格式化" class="headerlink" title="时间格式化"></a>时间格式化</h3><h4 id="js时间格式化"><a href="#js时间格式化" class="headerlink" title="js时间格式化"></a>js时间格式化</h4><p>主要实现了两个功能:</p>
<ol>
<li>时间格式化</li>
<li>两个时间日期差计算</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Times</span> </span>&#123;</span><br><span class="line">  <span class="keyword">constructor</span> (date = new Date()) &#123;</span><br><span class="line">    <span class="keyword">this</span>.date = <span class="keyword">this</span>.fix(date)</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  fix (date = <span class="keyword">this</span>.date) &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> date === <span class="string">'object'</span>) &#123;</span><br><span class="line">      <span class="keyword">let</span> fixDate = <span class="function">(<span class="params">n</span>) =&gt;</span> n &lt; <span class="number">10</span> ? <span class="string">'0'</span> + n : n</span><br><span class="line">      <span class="keyword">return</span> &#123;</span><br><span class="line">        <span class="string">'Y'</span>: date.getFullYear(), <span class="comment">// 年</span></span><br><span class="line">        <span class="string">'M'</span>: fixDate(date.getMonth() + <span class="number">1</span>), <span class="comment">//月</span></span><br><span class="line">        <span class="string">'D'</span>: fixDate(date.getDate()), <span class="comment">//日</span></span><br><span class="line">        <span class="string">'h'</span>: fixDate(date.getHours()), <span class="comment">//时</span></span><br><span class="line">        <span class="string">'m'</span>: fixDate(date.getMinutes()), <span class="comment">//分</span></span><br><span class="line">        <span class="string">'s'</span>: fixDate(date.getSeconds()), <span class="comment">//秒</span></span><br><span class="line">        <span class="string">'S'</span>: date.getMilliseconds(), <span class="comment">//毫秒,</span></span><br><span class="line">        <span class="string">'week'</span>: date.getDay() <span class="comment">// 周几</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">this</span>.fix(<span class="keyword">new</span> <span class="built_in">Date</span>(date))</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  format (rex = <span class="string">'Y-M-D h:m:s'</span>, date = <span class="keyword">this</span>.date) &#123;</span><br><span class="line">    <span class="keyword">let</span> temp = <span class="string">''</span></span><br><span class="line">    <span class="keyword">let</span> time = date</span><br><span class="line">    <span class="keyword">let</span> ttt = [...rex]</span><br><span class="line">    ttt.forEach(<span class="function"><span class="params">v</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">if</span> (<span class="built_in">Object</span>.keys(time).includes(v)) &#123;</span><br><span class="line">        temp += time[v]</span><br><span class="line">      &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        temp += v</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">return</span> temp</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  step (max, min, type = <span class="literal">true</span>, flag = <span class="literal">true</span>) &#123;</span><br><span class="line">    max = <span class="keyword">typeof</span> max === <span class="string">'object'</span> ? max : <span class="keyword">new</span> <span class="built_in">Date</span>(max)</span><br><span class="line">    min = <span class="keyword">typeof</span> min === <span class="string">'object'</span> ? min : <span class="keyword">new</span> <span class="built_in">Date</span>(min)</span><br><span class="line">    <span class="keyword">if</span> (max.getTime() &lt; min.getTime()) &#123; <span class="keyword">return</span> <span class="literal">false</span> &#125;</span><br><span class="line">    <span class="keyword">if</span> (type) &#123; <span class="keyword">return</span> <span class="keyword">this</span>.other(max.getTime() - min.getTime()) &#125;</span><br><span class="line">    <span class="keyword">let</span> tempMax = <span class="keyword">this</span>.fix(max)</span><br><span class="line">    <span class="keyword">let</span> tempMin = <span class="keyword">this</span>.fix(min)</span><br><span class="line">    <span class="keyword">let</span> O = [<span class="string">'Y'</span>, <span class="string">'M'</span>, <span class="string">'D'</span>, <span class="string">'h'</span>, <span class="string">'m'</span>, <span class="string">'s'</span>, <span class="string">'S'</span>]</span><br><span class="line">    <span class="keyword">let</span> result = <span class="built_in">Object</span>.keys(tempMax).map(<span class="function"><span class="params">v</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">let</span> temp = <span class="number">0</span></span><br><span class="line">      <span class="keyword">if</span> (tempMax[v] !== tempMin[v]) &#123;</span><br><span class="line">        temp = tempMax[v] - tempMin[v]</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">return</span> temp</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">if</span> (flag &amp;&amp; !result.every(<span class="function"><span class="params">v</span> =&gt;</span> v &gt;= <span class="number">0</span>))&#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">this</span>.other(max.getTime() - min.getTime())</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">let</span> date = &#123;&#125;</span><br><span class="line">    O.forEach(<span class="function">(<span class="params">v, i</span>) =&gt;</span> &#123; date[v] = result[i] &#125;)</span><br><span class="line">    <span class="keyword">return</span> date</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  other (t) &#123;</span><br><span class="line">    <span class="keyword">let</span> S = t % <span class="number">1000</span></span><br><span class="line">    <span class="keyword">let</span> tempS = (t - S) / <span class="number">1000</span></span><br><span class="line">    <span class="keyword">let</span> s = tempS % <span class="number">60</span></span><br><span class="line">    <span class="keyword">let</span> tempM = (tempS - s) / <span class="number">60</span></span><br><span class="line">    <span class="keyword">let</span> m = tempM % <span class="number">60</span></span><br><span class="line">    <span class="keyword">let</span> tempH = (tempM - m) / <span class="number">60</span></span><br><span class="line">    <span class="keyword">let</span> h = tempH % <span class="number">24</span></span><br><span class="line">    <span class="keyword">let</span> D = (tempH - h) / <span class="number">24</span></span><br><span class="line">    <span class="keyword">return</span> &#123;<span class="attr">Y</span>: <span class="number">0</span>, <span class="attr">M</span>: <span class="number">0</span>, D, h, m, s, S&#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> t = <span class="keyword">new</span> Times()</span><br><span class="line"><span class="comment">// 格式化</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'--t.format()--'</span>, t.format())</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'--t.date--'</span>, t.date)</span><br><span class="line"><span class="comment">// 计算两个时间日期差</span></span><br><span class="line"><span class="built_in">console</span>.log(t.format(<span class="string">'时间相差 D日h小时m分钟s秒'</span>, t.step(<span class="string">'2018-02-20 12:12:12'</span>, <span class="string">'2018-01-10 11:11:11'</span>)))</span><br><span class="line"><span class="built_in">console</span>.log(t.format(<span class="string">'时间相差 D日h小时m分钟s秒'</span>, t.step(<span class="string">'2018-02-20 12:12:12'</span>, <span class="string">'2018-01-10 11:11:11'</span>, <span class="literal">false</span>)))</span><br><span class="line"><span class="built_in">console</span>.log(t.format(<span class="string">'时间相差 Y年M月D日h小时m分钟s秒'</span>, t.step(<span class="string">'2018-02-20 12:12:12'</span>, <span class="string">'2018-01-10 11:11:11'</span>, <span class="literal">false</span>, <span class="literal">false</span>)))</span><br></pre></td></tr></table></figure>
<h3 id="H5-录音"><a href="#H5-录音" class="headerlink" title="H5 录音"></a>H5 录音</h3><p>最近有一个需求，实现语音消息<br>了解了一下 <a href="https://github.com/muaz-khan/RecordRTC" target="_blank" rel="noopener">RecordRTC</a><br>语音识别和合成,通过百度API实现</p>
<ol>
<li><p>首先获取麦克风权限 (https or 本地开发)</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia</span><br><span class="line"><span class="keyword">if</span> (navigator.getUserMedia) &#123;</span><br><span class="line">navigator.getUserMedia(&#123;<span class="attr">audio</span>: <span class="literal">true</span>&#125;, (stream) =&gt; &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'--授权--'</span>)</span><br><span class="line">  <span class="keyword">this</span>.rec = <span class="keyword">new</span> Record(&#123;<span class="attr">stream</span>: stream&#125;)</span><br><span class="line">&#125;, () =&gt; &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'--失败--'</span>)</span><br><span class="line">&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>录音以及本地预览</p>
</li>
<li>语音识别和合成</li>
</ol>
<h3 id="codewars算法题小记"><a href="#codewars算法题小记" class="headerlink" title="codewars算法题小记"></a>codewars算法题小记</h3><h4 id="全排列"><a href="#全排列" class="headerlink" title="全排列"></a>全排列</h4><p>Q: 什么是全排列<br>A: <a href="https://baike.baidu.com/item/%E5%85%A8%E6%8E%92%E5%88%97" target="_blank" rel="noopener">看这里</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> testArr = [<span class="string">'a'</span>,<span class="string">'b'</span>,<span class="string">'c'</span>,<span class="string">'d'</span>]</span><br><span class="line"><span class="keyword">let</span> a = test(testArr)</span><br><span class="line"><span class="built_in">console</span>.log(a,a.length)</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 递归 */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params">before,later</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">if</span>(!before.length)&#123;<span class="keyword">return</span> later&#125;</span><br><span class="line">  <span class="keyword">let</span> arr = []</span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>;i&lt;later.length;i++)&#123;</span><br><span class="line">    arr = arr.concat(addArr(before[before.length - <span class="number">1</span>],later[i]))</span><br><span class="line">  &#125;</span><br><span class="line">  before.pop()</span><br><span class="line">  <span class="keyword">return</span> f(before,arr)</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 做测试 */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params">arr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">if</span> (arr.length &gt; <span class="number">2</span>) &#123;</span><br><span class="line">    <span class="keyword">let</span> start = arr.splice(<span class="number">-3</span>, <span class="number">3</span>)</span><br><span class="line">    <span class="keyword">let</span> startArr = getAll(start)</span><br><span class="line">    <span class="keyword">return</span> f(arr, startArr)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> addArr(arr[<span class="number">0</span>],arr.slice(<span class="number">1</span>))</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 依次插入数组 */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">addArr</span>(<span class="params">n,arr</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">let</span> all = []</span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">let</span> i= <span class="number">0</span>;i&lt;arr.length + <span class="number">1</span>;i++)&#123;</span><br><span class="line">    <span class="keyword">let</span> tempArr = <span class="built_in">Array</span>.from(arr)</span><br><span class="line">    tempArr.splice(i,<span class="number">0</span>,n)</span><br><span class="line">    all.push(tempArr)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> all</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 输出数组的依次左移的结果 */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getAll</span>(<span class="params">arr</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">let</span> all = []</span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>;i&lt;arr.length;i++)&#123;</span><br><span class="line">    <span class="keyword">let</span> a = arr.shift()</span><br><span class="line">    <span class="keyword">let</span> b = arr.concat(a)</span><br><span class="line">    all.push(b)</span><br><span class="line">    all.unshift(<span class="built_in">Array</span>.from(b).reverse())</span><br><span class="line">    arr.push(a)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> all</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="数组倒序-不使用reverse"><a href="#数组倒序-不使用reverse" class="headerlink" title="数组倒序 不使用reverse"></a><a href="https://www.codewars.com/kata/reverse-it-quickly/train/javascript" target="_blank" rel="noopener">数组倒序 不使用reverse</a></h4><h5 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h5><p><img src="/images/sort.png" alt="数组倒序问题图"><br><strong>限制28个字符</strong>,除去<code>weirdReverse=a=&gt;</code>,还有12个字符</p>
<h5 id="记录"><a href="#记录" class="headerlink" title="记录"></a>记录</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">weirdReverse=<span class="function"><span class="params">a</span>=&gt;</span>a.map(<span class="function">(<span class="params">i</span>)=&gt;</span>a.slice(-i<span class="number">-1</span>)[<span class="number">0</span>])</span><br><span class="line">weirdReverse=<span class="function"><span class="params">a</span>=&gt;</span>a.map(<span class="function">(<span class="params">v,i</span>)=&gt;</span>a[a.length-i<span class="number">-1</span>])</span><br><span class="line">weirdReverse=<span class="function"><span class="params">a</span>=&gt;</span>a.sort(<span class="function">(<span class="params">b,l</span>)=&gt;</span>&#123;a.indexOf(b)-a.indexOf(l)&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 然而这样的字符长度...</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 最终的答案竟让我木凳狗呆</span></span><br><span class="line">weirdReverse=<span class="function"><span class="params">a</span>=&gt;</span>a.sort(<span class="function"><span class="params">s</span>=&gt;</span><span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h3 id="获取DevTools的状态-在打开时做一些事情"><a href="#获取DevTools的状态-在打开时做一些事情" class="headerlink" title="获取DevTools的状态,在打开时做一些事情"></a>获取DevTools的状态,在打开时做一些事情</h3> <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> element = <span class="keyword">new</span> Image()</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(element, <span class="string">'id'</span>, &#123;</span><br><span class="line">  get: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">/* TODO */</span></span><br><span class="line">    alert(<span class="string">'Open'</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'%cHello'</span>, element)</span><br></pre></td></tr></table></figure>
<p> 原理：<br> 控制台输出的内容如果是对象（包括正则表达式对象），则保留的是对象的引用，输出的会是对象的实时值，即对象内容被改变时，能够反映其变化（前提是重新开启控制台）。实际上是每次关闭再开启控制台的时候，重新调用对象的toString方法。<br> 另外这个方法是可以被破解的，只要在控制台右键调出相关菜单，点“Clear Console”，就全没了。<br> 相关资料:</p>
<ul>
<li>Stack Overflow <a href="https://stackoverflow.com/questions/7798748/find-out-whether-chrome-console-is-open" target="_blank" rel="noopener">Find out whether Chrome console is open</a></li>
<li>git库  <a href="https://github.com/sindresorhus/devtools-detect" target="_blank" rel="noopener">devtools-detect</a> </li>
</ul>
<h3 id="IndexedDB"><a href="#IndexedDB" class="headerlink" title="IndexedDB"></a><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/IndexedDB_API" target="_blank" rel="noopener">IndexedDB</a></h3><p>相关资料:<br><a href="http://javascript.ruanyifeng.com/bom/indexeddb.html" target="_blank" rel="noopener">indexeddb-阮一峰</a><br><a href="https://github.com/Hokkaidosunny/indexdb-api" target="_blank" rel="noopener">实现的git库</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Title<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">h3</span>&gt;</span>dsad<span class="tag">&lt;/<span class="name">h3</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="class"><span class="keyword">class</span> <span class="title">DB</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">constructor</span> (&#123;</span></span><br><span class="line"><span class="javascript">                   name = <span class="string">'myDB'</span>,</span></span><br><span class="line"><span class="undefined">                   version = 1,</span></span><br><span class="line"><span class="javascript">                   defaultStoreName = <span class="string">'default'</span>,</span></span><br><span class="line"><span class="javascript">                   log = <span class="literal">true</span>,</span></span><br><span class="line"><span class="undefined">                   rule = &#123;</span></span><br><span class="line"><span class="javascript">                     keyPath: <span class="literal">null</span>,</span></span><br><span class="line"><span class="javascript">                     autoIncrement: <span class="literal">false</span></span></span><br><span class="line"><span class="undefined">                   &#125;</span></span><br><span class="line"><span class="undefined">                 &#125; = &#123;&#125;) &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.db = <span class="string">''</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.name = name</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.verison = version</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.defaultStoreName = defaultStoreName</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.env = log</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.rule = rule</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.addDB()</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 自定义log */</span></span></span><br><span class="line"><span class="undefined">    log (str) &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">return</span> <span class="keyword">this</span>.env ? <span class="built_in">window</span>.console.log(<span class="string">'%c&gt;&gt;'</span>, <span class="string">'color:white;background:green'</span>, str) : <span class="keyword">this</span>.env</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 连接数据库 */</span></span></span><br><span class="line"><span class="undefined">    open () &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> openRequest = <span class="built_in">window</span>.indexedDB.open(<span class="keyword">this</span>.name, <span class="keyword">this</span>.verison)</span></span><br><span class="line"><span class="javascript">        openRequest.onsuccess = <span class="function"><span class="params">e</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(<span class="string">'--连接成功--'</span>)</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.db = e.target.result</span></span><br><span class="line"><span class="undefined">          resolve(e.target.result)</span></span><br><span class="line"><span class="undefined">        &#125;</span></span><br><span class="line"><span class="javascript">        openRequest.onupgradeneeded = <span class="function"><span class="params">e</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(<span class="string">'--第一次打开该数据库，或者数据库版本发生变化。--'</span>)</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.db = e.target.result</span></span><br><span class="line"><span class="undefined">          resolve(e.target.result)</span></span><br><span class="line"><span class="undefined">        &#125;</span></span><br><span class="line"><span class="javascript">        openRequest.onblocked = <span class="function"><span class="params">e</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(<span class="string">'--上一次的数据库连接还未关闭!--'</span>)</span></span><br><span class="line"><span class="undefined">        &#125;</span></span><br><span class="line"><span class="javascript">        openRequest.onerror = <span class="function"><span class="params">e</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(<span class="string">'--连接失败--'</span>)</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(e)</span></span><br><span class="line"><span class="undefined">          reject(e)</span></span><br><span class="line"><span class="undefined">        &#125;</span></span><br><span class="line"><span class="undefined">      &#125;)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 增加数据库 */</span></span></span><br><span class="line"><span class="undefined">    addDB () &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (<span class="keyword">this</span>.db !== <span class="string">''</span>) &#123; <span class="keyword">this</span>.db.close() &#125;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">this</span>.open()</span></span><br><span class="line"><span class="javascript">        .then(<span class="function"><span class="params">db</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">let</span> store = db.createObjectStore(<span class="keyword">this</span>.defaultStoreName, <span class="keyword">this</span>.rule)</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(store)</span></span><br><span class="line"><span class="undefined">        &#125;)</span></span><br><span class="line"><span class="javascript">        .catch(<span class="function"><span class="params">e</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="keyword">this</span>.log(e)</span></span><br><span class="line"><span class="undefined">        &#125;)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 删除数据库 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 修改数据库 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 查询数据库 */</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 增加数据库ObjStore */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 删除数据库ObjStore */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 修改数据库ObjStore */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 查询数据库ObjStore */</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 增加索引 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 删除索引 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 修改索引 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 查询索引 */</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 增 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 删 */</span></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 改 */</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">    <span class="comment">/* 查 */</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="undefined">    createIndex () &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (<span class="keyword">this</span>.db !== <span class="string">''</span>) &#123; <span class="keyword">this</span>.db.close() &#125;</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* eslint-disable */</span></span></span><br><span class="line"><span class="javascript">  <span class="keyword">var</span> db = <span class="string">''</span></span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">createTabel</span> (<span class="params">name</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    indexedDB.open(<span class="string">'library'</span>, <span class="number">2</span>).onupgradeneeded = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      e.target.result.createObjectStore(<span class="string">'book222'</span>, &#123;<span class="attr">keyPath</span>: <span class="string">'author'</span>&#125;)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 创建索引 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">createIndex</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> oldVersion = db.version</span></span><br><span class="line"><span class="javascript">    <span class="built_in">console</span>.log(db.version)</span></span><br><span class="line"><span class="undefined">    db.close()</span></span><br><span class="line"><span class="javascript">    openDB(&#123;<span class="attr">name</span>: <span class="string">'libraty'</span>, <span class="attr">version</span>: oldVersion + <span class="number">1</span>&#125;, <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'--连接成功--'</span>)</span></span><br><span class="line"><span class="javascript">    &#125;, <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">/* 修改index */</span></span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Upgrading...'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> objectStore = e.target.transaction.objectStore(<span class="string">'books'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> indexNames = objectStore.indexNames</span></span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (indexNames.contains(<span class="string">'Name'</span>)) &#123;</span></span><br><span class="line"><span class="javascript">        objectStore.deleteIndex(<span class="string">'Name'</span>)</span></span><br><span class="line"><span class="undefined">      &#125;</span></span><br><span class="line"><span class="javascript">      objectStore.createIndex(<span class="string">'Name'</span>, <span class="string">'title'</span>, &#123;<span class="attr">unique</span>: <span class="literal">true</span>&#125;)</span></span><br><span class="line"><span class="undefined">    &#125;)</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">openDB</span> (<span class="params">&#123;name = <span class="string">'library'</span>, version = <span class="number">1</span>&#125;, callback1, callback2</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> openRequest = indexedDB.open(name, version)</span></span><br><span class="line"><span class="javascript">    openRequest.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="undefined">      db = e.target.result</span></span><br><span class="line"><span class="undefined">      callback1()</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onupgradeneeded = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 此数据库此前不存在，进行初始化</span></span></span><br><span class="line"><span class="undefined">      db = e.target.result</span></span><br><span class="line"><span class="javascript">      <span class="comment">// var store = db.createObjectStore('books', &#123;keyPath: 'isbn'&#125;)</span></span></span><br><span class="line"><span class="javascript">      <span class="comment">// store.add(&#123;title: 'Quarry Memories', author: 'Fred', isbn: 123456&#125;)</span></span></span><br><span class="line"><span class="undefined">      callback2(e)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onblocked = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'blocked!'</span>)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Error'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.dir(e)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">goDB</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> openRequest = indexedDB.open(<span class="string">'library'</span>)</span></span><br><span class="line"><span class="javascript">    openRequest.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'--连接成功--'</span>)</span></span><br><span class="line"><span class="undefined">      db = e.target.result</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onupgradeneeded = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Upgrading...'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="comment">// 此数据库此前不存在，进行初始化</span></span></span><br><span class="line"><span class="undefined">      db = e.target.result</span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> store = db.createObjectStore(<span class="string">'books'</span>, &#123;<span class="attr">keyPath</span>: <span class="string">'isbn'</span>&#125;)</span></span><br><span class="line"><span class="javascript">      store.add(&#123;<span class="attr">title</span>: <span class="string">'Quarry Memories'</span>, <span class="attr">author</span>: <span class="string">'Fred'</span>, <span class="attr">isbn</span>: <span class="number">123456</span>&#125;)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onblocked = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'blocked!'</span>)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    openRequest.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Error'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.dir(e)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">Task</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> tx = db.transaction(<span class="string">'books'</span>, <span class="string">'readwrite'</span>)</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> store = tx.objectStore(<span class="string">'books'</span>)</span></span><br><span class="line"><span class="javascript">    <span class="comment">/**/</span></span></span><br><span class="line"><span class="javascript">    tx.onabort = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'事务执行中止'</span>)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    tx.oncomplete = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'事务执行完毕'</span>)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    tx.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'事务执行失败'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">return</span> store</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 增 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">setData</span> (<span class="params">data</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().add(data)</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Add Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Add Ok'</span>, res.result)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 删 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">delData</span> (<span class="params">data</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().delete(data)</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Delete Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Delete Ok'</span>, res.result)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 改 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">putData</span> (<span class="params">data</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().put(data)</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Put Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Put Ok'</span>, res.result)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 查 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">getData</span> (<span class="params">data</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().get(data)</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Get Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Get Ok'</span>, res.result)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* index */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">getData</span> (<span class="params">data</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().index(<span class="string">'isbn'</span>).get(data)</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Get Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'Get Ok'</span>, res.result)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span></span><br><span class="line"><span class="javascript">  <span class="comment">/* 遍历 */</span></span></span><br><span class="line"><span class="javascript">  <span class="function"><span class="keyword">function</span> <span class="title">ForData</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> res = Task().openCursor()</span></span><br><span class="line"><span class="javascript">    res.onerror = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'For Error'</span>, e.target.error.name)</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="javascript">    res.onsuccess = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span></span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">'For Ok'</span>)</span></span><br><span class="line"><span class="javascript">      <span class="keyword">var</span> res = e.target.result</span></span><br><span class="line"><span class="javascript">      <span class="keyword">if</span> (res) &#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'Key'</span>, res.key)</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'Data'</span>, res.value)</span></span><br><span class="line"><span class="undefined">        res.continue()</span></span><br><span class="line"><span class="undefined">      &#125;</span></span><br><span class="line"><span class="undefined">    &#125;</span></span><br><span class="line"><span class="undefined">  &#125;</span></span><br><span class="line"><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="electron"><a href="#electron" class="headerlink" title="electron"></a><a href="https://electronjs.org/" target="_blank" rel="noopener">electron</a></h3><p>Electron是由Github开发，用HTML，CSS和JavaScript来构建跨平台桌面应用程序的一个开源库。</p>
<h4 id="electron-vue"><a href="#electron-vue" class="headerlink" title="electron-vue"></a><a href="https://simulatedgreg.gitbooks.io/electron-vue/content/cn/" target="_blank" rel="noopener">electron-vue</a></h4><h3 id="three-js"><a href="#three-js" class="headerlink" title="three.js"></a><a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a></h3><h4 id="Three-js入门指南"><a href="#Three-js入门指南" class="headerlink" title="Three.js入门指南"></a><a href="http://www.ituring.com.cn/book/1272" target="_blank" rel="noopener">Three.js入门指南</a></h4>

    </div>







      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">




      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/zfb.png" alt="zhangyuhan2016 支付宝"/>
        <p>支付宝</p>
      </div>




  </div>
</div>

      </div>




    <footer class="post-footer">

        <div class="post-tags">

            <a href="/tags/chrome/" rel="tag">chrome</a>

            <a href="/tags/js/" rel="tag">js</a>

            <a href="/tags/indexedDB/" rel="tag">indexedDB</a>

            <a href="/tags/算法/" rel="tag">算法</a>

        </div>







        <div class="post-nav">
          <div class="post-nav-next post-nav-item">

              <a href="/2017/12/12/WebStorm-note/" rel="next" title="WebStorm备忘">
                <i class="fa fa-chevron-left"></i> WebStorm备忘
              </a>

          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">

              <a href="/2017/12/15/vue-deploy/" rel="prev" title="搭建vue开发脚手架">
                搭建vue开发脚手架 <i class="fa fa-chevron-right"></i>
              </a>

          </div>
        </div>




    </footer>
  </div>



  </article>



    <div class="post-spread">

    </div>
  </div>


          </div>






    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>





        </div>



  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">

    <div class="sidebar-inner">




        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>


      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">

              <img class="site-author-image" itemprop="image"
                src="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4"
                alt="zhangyuhan2016" />

              <p class="site-author-name" itemprop="name">zhangyuhan2016</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">


              <div class="site-state-item site-state-posts">

                <a href="/archives/">

                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>







              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">30</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>


          </nav>



          <div class="links-of-author motion-element">


                <span class="links-of-author-item">
                  <a href="https://github.com/zhangyuhan2016" target="_blank" title="GitHub">

                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>


          </div>








        </div>
      </section>


      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">






              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Vue调用组件函数"><span class="nav-number">1.</span> <span class="nav-text"><a href="#Vue&#x8C03;&#x7528;&#x7EC4;&#x4EF6;&#x51FD;&#x6570;" class="headerlink" title="Vue&#x8C03;&#x7528;&#x7EC4;&#x4EF6;&#x51FD;&#x6570;"></a>Vue&#x8C03;&#x7528;&#x7EC4;&#x4EF6;&#x51FD;&#x6570;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Unicode与JavaScript"><span class="nav-number">2.</span> <span class="nav-text"><a href="#Unicode&#x4E0E;JavaScript" class="headerlink" title="Unicode&#x4E0E;JavaScript"></a>Unicode&#x4E0E;JavaScript</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#时间格式化"><span class="nav-number">3.</span> <span class="nav-text"><a href="#&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;" class="headerlink" title="&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;"></a>&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#js时间格式化"><span class="nav-number">3.1.</span> <span class="nav-text"><a href="#js&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;" class="headerlink" title="js&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;"></a>js&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5316;</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#说明"><span class="nav-number">3.2.</span> <span class="nav-text"><a href="#&#x8BF4;&#x660E;" class="headerlink" title="&#x8BF4;&#x660E;"></a>&#x8BF4;&#x660E;</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#H5-录音"><span class="nav-number">4.</span> <span class="nav-text"><a href="#H5-&#x5F55;&#x97F3;" class="headerlink" title="H5 &#x5F55;&#x97F3;"></a>H5 &#x5F55;&#x97F3;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#codewars算法题小记"><span class="nav-number">5.</span> <span class="nav-text"><a href="#codewars&#x7B97;&#x6CD5;&#x9898;&#x5C0F;&#x8BB0;" class="headerlink" title="codewars&#x7B97;&#x6CD5;&#x9898;&#x5C0F;&#x8BB0;"></a>codewars&#x7B97;&#x6CD5;&#x9898;&#x5C0F;&#x8BB0;</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#全排列"><span class="nav-number">5.1.</span> <span class="nav-text"><a href="#&#x5168;&#x6392;&#x5217;" class="headerlink" title="&#x5168;&#x6392;&#x5217;"></a>&#x5168;&#x6392;&#x5217;</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#数组倒序-不使用reverse"><span class="nav-number">5.2.</span> <span class="nav-text"><a href="#&#x6570;&#x7EC4;&#x5012;&#x5E8F;-&#x4E0D;&#x4F7F;&#x7528;reverse" class="headerlink" title="&#x6570;&#x7EC4;&#x5012;&#x5E8F; &#x4E0D;&#x4F7F;&#x7528;reverse"></a><a href="https://www.codewars.com/kata/reverse-it-quickly/train/javascript" target="_blank" rel="noopener">&#x6570;&#x7EC4;&#x5012;&#x5E8F; &#x4E0D;&#x4F7F;&#x7528;reverse</a></span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#问题描述"><span class="nav-number">5.2.1.</span> <span class="nav-text"><a href="#&#x95EE;&#x9898;&#x63CF;&#x8FF0;" class="headerlink" title="&#x95EE;&#x9898;&#x63CF;&#x8FF0;"></a>&#x95EE;&#x9898;&#x63CF;&#x8FF0;</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#记录"><span class="nav-number">5.2.2.</span> <span class="nav-text"><a href="#&#x8BB0;&#x5F55;" class="headerlink" title="&#x8BB0;&#x5F55;"></a>&#x8BB0;&#x5F55;</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取DevTools的状态-在打开时做一些事情"><span class="nav-number">6.</span> <span class="nav-text"><a href="#&#x83B7;&#x53D6;DevTools&#x7684;&#x72B6;&#x6001;-&#x5728;&#x6253;&#x5F00;&#x65F6;&#x505A;&#x4E00;&#x4E9B;&#x4E8B;&#x60C5;" class="headerlink" title="&#x83B7;&#x53D6;DevTools&#x7684;&#x72B6;&#x6001;,&#x5728;&#x6253;&#x5F00;&#x65F6;&#x505A;&#x4E00;&#x4E9B;&#x4E8B;&#x60C5;"></a>&#x83B7;&#x53D6;DevTools&#x7684;&#x72B6;&#x6001;,&#x5728;&#x6253;&#x5F00;&#x65F6;&#x505A;&#x4E00;&#x4E9B;&#x4E8B;&#x60C5;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IndexedDB"><span class="nav-number">7.</span> <span class="nav-text"><a href="#IndexedDB" class="headerlink" title="IndexedDB"></a><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/IndexedDB_API" target="_blank" rel="noopener">IndexedDB</a></span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#electron"><span class="nav-number">8.</span> <span class="nav-text"><a href="#electron" class="headerlink" title="electron"></a><a href="https://electronjs.org/" target="_blank" rel="noopener">electron</a></span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#electron-vue"><span class="nav-number">8.1.</span> <span class="nav-text"><a href="#electron-vue" class="headerlink" title="electron-vue"></a><a href="https://simulatedgreg.gitbooks.io/electron-vue/content/cn/" target="_blank" rel="noopener">electron-vue</a></span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#three-js"><span class="nav-number">9.</span> <span class="nav-text"><a href="#three-js" class="headerlink" title="three.js"></a><a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a></span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Three-js入门指南"><span class="nav-number">9.1.</span> <span class="nav-text"><a href="#Three-js&#x5165;&#x95E8;&#x6307;&#x5357;" class="headerlink" title="Three.js&#x5165;&#x95E8;&#x6307;&#x5357;"></a><a href="http://www.ituring.com.cn/book/1272" target="_blank" rel="noopener">Three.js&#x5165;&#x95E8;&#x6307;&#x5357;</a></span></a></li></ol></li></ol></div>


          </div>
        </section>
      <!--/noindex-->




    </div>
    <div class="post-block page my-thanks">
        <div class="my-title">致谢</div>
        <div class="thanks">Hexo</div>
        <div class="thanks">Next & Gemini</div>
        <div class="thanks">Gitee</div>
    </div>
  </aside>



      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">









      </div>
    </footer>


      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>

      </div>




  </div>



<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>



























    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>




    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>




    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>




    <script type="text/javascript" src="/lib/three/three.min.js"></script>




    <script type="text/javascript" src="/lib/three/canvas_lines.min.js"></script>






  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>







  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>




  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>






  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>









      <script id="dsq-count-scr" src="https://.disqus.com/count.js" async></script>



      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://zhangyuhan2016.gitee.io/2017/12/14/new-Get/';
          this.page.identifier = '2017/12/14/new-Get/';
          this.page.title = 'new Get';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>






























  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>

  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: true,
        notify: false,
        appId: 'xxTmc7jwpAd2bWhmkKOI7IGY-gzGzoHsz',
        appKey: 'glPUiD8ljbJsKYhBg5E0ghII',
        placeholder: '说点什么呗 ヾﾉ≧∀≦)o',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>












  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("mpOMyFHLi7a5S0ka5mv3cz7C-gzGzoHsz", "3t0W0au9Mxf0lOGFDF8u89pc");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>
















</body>
</html>
